<?php

//ask for the shopping cart ID contained inside the cookie
$shoppingcart_id = $_COOKIE["shoppingcart_id"];

//extract all the items from database (a table containing items)
$items = mysql_query("SELECT * FROM items");

//extract the array for every single item
while($item = mysql_fetch_array($items))
	{
	//find out the id of the item
	$item_id = $item["ID"];
	
	//count the number of items with having the selected ID contained insinde the shopping cart
	//we use the relation table between the items and the carts
	//(result could be 0 or 1)
	$items_nr = mysql_query("SELECT COUNT(*) AS NR FROM rel WHERE ITEM_ID = '$item_id' AND CART_ID = '$shoppingcart_id'");
	
	//fetch array from resulting table (a one row table so we do not another WHILE)
	$item_nr = mysql_fetch_array($items_nr);
	
	//check the value of the result inside the array
	if($item_nr["NR"] > 0)
		{
		//the item is already inside the shopping cart.
		//we display the DELETE FROM CART button
		}
	else
		{
		//the item is not inside the shopping cart.
		//we display the ADD TO CART button
		}
	}
?>